<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<html>
<head>
<title></title>
<%@include file="/common/meta.jsp"%>
<%@include file="/common/ec.jsp"%>
<style type="text/css">
.budgetTable {
	margin: 5px;
	border-top: 1px solid #000000;
	border-left: 1px solid #000000;
}

.budgetTable tr td {
	height: 25px;
	border-bottom: 1px solid #000000;
	border-right: 1px solid #000000;
	font-family: sans-serif;
	padding: 2px;
}

.budgetTable tr th {
	font-size: 13px;
	background-color: #ECECEC;
	text-align: center;
	border-bottom: 1px solid #000000;
	border-right: 1px solid #000000;
	font-family: sans-serif;
	font-weight: normal;
	height: 25px;
	padding: 0px;
}
.amount{
	color: green;
	border:0px;
	font-family: sans-serif;
	text-align: right;
	width: 95px;
}
.thdiv{
	height: 15px;
}
.yen{
	color: red;
	margin: auto 5px;
	font-weight: bold;
}
</style>
<script type="text/javascript">
  function sumAmount(itemId){
	  items = document.getElementsByName(itemId);
	  amount = 0;
	  for(var i = 0; i < items.length; i++){
		  amount = amount + parseFloat(items[i].amount);
	  }
	  document.getElementById(itemId + "_sum").value = amount;
  }
</script>
</head>
<body>
<div>
  <%
    int size = 0; 
    int index = 0;
  %>
  <s:iterator value="#attr.depts">
     <%size++; %>
  </s:iterator>
  <table id="tableData" name="tableData" class="budgetTable" cellpadding="0" cellspacing="0" width="<%=100 * size + 350%>">
    <tr>
      <th colspan="<%=size + 4%>" style="text-align: left; padding-left: 10px;">
      	预算全貌&nbsp;&nbsp;&nbsp;&nbsp;
      	部门：<span style="color: green">${loginDept.name }</span>&nbsp;&nbsp;&nbsp;&nbsp;
      	年度：<span style="color: green">${budgetYear}</span>
      </th>
    </tr>
    <tr>
      <th width="50">序号</th>
      <th width="100">科目编码</th>
      <th width="100">科目名称</th>
      <s:iterator value="#attr.depts" var="dept">
      <th width="100">
        <div class="thdiv">${dept.name}</div>
        <div class="thdiv" style="color: green; border-top: 1px solid black;">SN：${dept.serialNo}</div>
      </th>
      </s:iterator>
      <th width="100">合计<span class="yen">&yen;</span></th>
    </tr>
	<s:iterator value="#attr.budgetItems" var="item">
	<%index++; %>
	<tr>
	  <td align="center"><%=index %></td>
	  <td>${item.code}</td>
	  <td>${item.name}</td>
	  <s:iterator value="#attr.depts" var="dept">
      <td width="100" align="right">
      	<span class="amount">
      	<cbcs:budgetItem itemId="${item.id}" deptId="${dept.id}" year="${budgetYear}"></cbcs:budgetItem></span>
      </td>
      </s:iterator>
      <td align="right">
        <span class="amount">
        <cbcs:itemSumAmount deptSerialNo="${loginDept.serialNo}" itemId="${item.id}" year="${budgetYear}"></cbcs:itemSumAmount>
        </span>
      </td>
	</tr>
	</s:iterator>
  </table>
</div>
<input type="button" onclick="AllAreaExcel()" class="button" value="excel导出">
<script type="text/javascript">
	
	function AllAreaExcel() {
		if (!confirm('是否要导出到Excel?')) {
			return;
		}
		try {
			var oXL = new ActiveXObject("Excel.Application");
			var oWB = oXL.Workbooks.Add();
			var oSheet = oWB.ActiveSheet;
			var sel = document.body.createTextRange();
			sel.moveToElementText(tableData);
			sel.select();
			sel.execCommand("Copy");
			oSheet.Paste();
			oXL.Visible = true;
		} catch (e) {
			alert("1.Excel导出没有成功.\n\n" + 
				  "2." + e.message + ".\n\n" +
				  "3.您的电脑可能没有安装Microsoft Excel软件.\n\n" + 
				  "4.请设置Internet选项自定义级别,对没有标记安全级别的 ActiveX控件进行提示.");
		}
	}
</script>
</body>
</html>